Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

500
Views
Error de prueba de Nest.js: el uso de la instrucción "extiende registrador" no está permitido en Nest v8. Por favor, use "extiende ConsoleLogger" en su lugar

Aquí está el problema que tengo:

Estoy usando mi registrador personalizado en Nest.js:

 export class ReportLogger extends ConsoleLogger { verbose(message: string) { console.log('【Verbose】Reporting', message); super.verbose.apply(this, arguments); } log(message: string) { console.log('【Log】Reporting', message); super.log.apply(this, arguments); } }

Y el archivo log.interceptor.ts :

 export class LogInterceptor implements NestInterceptor { constructor(private reportLogger: ReportLogger) { this.reportLogger.setContext('LogInterceptor'); } intercept(context: ExecutionContext, next: CallHandler) { const http = context.switchToHttp(); const request = http.getRequest(); const now = Date.now(); return next .handle() .pipe( tap(() => this.reportLogger.log( `${request.method} ${request.url} ${Date.now() - now}ms`, ), ), ); } }

Y aquí está el archivo main.ts :

 async function bootstrap() { const reportLogger = new ReportLogger(); const app = await NestFactory.create<NestExpressApplication>(AppModule, { cors: { origin: ['http://localhost', 'http://localhost:3000'], credentials: true, }, bufferLogs: true, logger: reportLogger, }); app.useGlobalInterceptors( new LogInterceptor(reportLogger), ); setupSwagger(app); await app.listen(4200); }

Cuando ejecuto npm run start:dev para ejecutar la aplicación Nest en el desarrollador, todo funciona bien. Pero cuando ejecuto npm run test:e2e o npm run test on testing, muestra este error:

 Using the "extends Logger" instruction is not allowed in Nest v8. Please, use "extends ConsoleLogger" instead. 10 | const moduleFixture: TestingModule = await Test.createTestingModule({ 11 | imports: [AppModule], > 12 | }).compile(); | ^ 13 | 14 | app = moduleFixture.createNestApplication(); 15 | await app.init();

Leí el documento de Nest.js nuevamente y encontré el cambio de ruptura de registro en los documentos. Pero la pregunta es que ya hice que mi ReportLogger extienda ConsoleLogger, ¿por qué aparece este error nuevamente? ¿Y por qué solo se muestra en las pruebas?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

incluso con "@nestjs/testing": "^8.0.7" este problema aún ocurre

 class Logger implements LoggerService { ... } await Test.createTestingModule({ imports: [ApiModule], }) .setLogger(new Logger()) .compile();

configurar la instancia del registrador resuelve ese error de mi lado

over 4 years ago · Santiago Trujillo Report

0

Enfrenté el mismo problema después de actualizar NestJS a la versión 8.

Más tarde, descubrí que el paquete @nestjs/testing tenía instalada una versión anterior y no se actualizó a la última versión. El motivo es que la versión anterior del módulo de prueba de NestJS está utilizando el registrador antiguo.

Para solucionar este problema, solo necesita actualizar el módulo de prueba de NestJS.

Ejecute este comando para la última versión:

 npm i @nestjs/testing@latest

O versión específica

 npm i @nestjs/testing@8.0.6 // <--- Change the NestJS version here

Después de esto, simplemente construya y ejecute casos de prueba nuevamente.

Enlaces externos:

  • Prueba de NPM de NestJS
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!